package com.weixin.paleituo.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.GoodsStoreActivity;
import com.weixin.paleituo.activity.OrderDetailsActivity;
import com.weixin.paleituo.base.BaseOrderRecycleAdapter;
import com.weixin.paleituo.bean.GoodsListBean;
import com.weixin.paleituo.bean.StoreListBean;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.eventbus.CanceOrderEvent;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.MyHorizontalScrollView;
import com.weixin.paleituo.view.TipsDialog;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Author yichao
 * Time  2018/4/7 17:51
 * Dest  取消订单
 */

public class CancelOrderRecycleAdapter extends BaseOrderRecycleAdapter {


    public CancelOrderRecycleAdapter(Context context, List<StoreListBean> storeListBeans) {
        super(context, storeListBeans);
    }
    @Override
    protected void setNoCustomCancleData(NoCustomCancleViewHolder noCustomCancleViewHolder, final StoreListBean storeListBean, List<GoodsListBean> goodsList, final int position) {
        String storeName = storeListBean.getStoreName();
        if (!StringUtils.isEmpty(storeName) && storeName.equals("舒社")) {
            noCustomCancleViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.shushe_logo);
            noCustomCancleViewHolder.mTvStoreNameItemOrderHead.setText("舒社");
            noCustomCancleViewHolder.mIvMoreItemOrderHead.setVisibility(View.INVISIBLE);
        } else {
            noCustomCancleViewHolder.mIvMoreItemOrderHead.setVisibility(View.VISIBLE);
            noCustomCancleViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.store_cart);
            noCustomCancleViewHolder.mTvStoreNameItemOrderHead.setText(storeListBean.getStoreName());
            noCustomCancleViewHolder.mLlStorerootItemOrderHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
                }
            });
        }

        HorizontalScrollViewGoodsItemAdapter horizontalScrollViewGoodsItemAdapter=new HorizontalScrollViewGoodsItemAdapter(mContext, (ArrayList<GoodsListBean>) goodsList);

        noCustomCancleViewHolder.mIdHorizontalScrollViewItemNocustomAwaitfor.initDatas(horizontalScrollViewGoodsItemAdapter);

        noCustomCancleViewHolder.mTvGoodsnumberCustomForPricing.setText("共" + storeListBean.getNum() + "件商品  需付款:");
        noCustomCancleViewHolder.mTvAwaitpayforCustomForPricing.setText("￥" + UIUtils.getMoney( storeListBean.getActualPrice()));
        noCustomCancleViewHolder.mIdHorizontalScrollViewItemNocustomAwaitfor.setOnItemClickListener(new MyHorizontalScrollView.OnItemClickListener() {
            @Override
            public void onClick(View view, int pos) {
                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(), storeListBean.getDetailId() + "");
                mContext.startActivity(intent);
            }
        });
        noCustomCancleViewHolder.mIvDelItemCancelOrderHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             //   ToastUtils.makeText("删除");
                showGotGoodsDialog(position,"确定删除订单","取消","确定", Contans.DELETE_ORDER_TYPE);

            }
        });
        noCustomCancleViewHolder.mLlNocustomRightLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(),null);
                mContext.startActivity(intent);
            }
        });

    }
    /**
     * 弹窗
     * @param position
     * @param content
     * @param left
     * @param right
     */
    private TipsDialog mTipsDialog;
    private void showGotGoodsDialog(final int position, final String content, String left , String right, final int type) {

        mTipsDialog = new TipsDialog.Builder(mContext)
                .setCancelClickListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        mTipsDialog.dismiss();
                    }
                })
                .setContentView(content)
                .setLeftButton(left, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mTipsDialog.dismiss();
                    }
                })
                .setRightButton(right, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mTipsDialog.dismiss();

                        EventBus.getDefault().post(new CanceOrderEvent(position,type));


                    }
                })
                .build();

        mTipsDialog.show();
    }
    @Override
    protected void setCustomCancleData(CustomCancleViewHolder customCancleViewHolder, final StoreListBean storeListBean, List<GoodsListBean> goodsList, final int position) {
        String storeName = storeListBean.getStoreName();
        if (!StringUtils.isEmpty(storeName) && storeName.equals("舒社")) {
            customCancleViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.shushe_logo);
            customCancleViewHolder.mTvStoreNameItemOrderHead.setText("舒社");
            customCancleViewHolder.mIvMoreItemOrderHead.setVisibility(View.INVISIBLE);
        } else {
            customCancleViewHolder.mIvMoreItemOrderHead.setVisibility(View.VISIBLE);
            customCancleViewHolder.mIvIconItemOrderHead.setImageResource(R.mipmap.store_cart);
            customCancleViewHolder.mTvStoreNameItemOrderHead.setText(storeListBean.getStoreName());
            customCancleViewHolder.mLlStorerootItemOrderHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GoodsStoreActivity.startActivity(mContext,storeListBean.getStoreId());
                }
            });
        }
        Glide.with(mContext).load(goodsList.get(0).getListUrl()).into(customCancleViewHolder.mIvGoodsiconCustomForPricing);
        customCancleViewHolder.mTvMessgeCustomForPricing.setText(storeListBean.getMsg() + "");
        customCancleViewHolder.mTvGoodsnumberCustomForPricing.setText("共" + storeListBean.getNum() + "件商品  需付款:");
        customCancleViewHolder.mTvAwaitpayforCustomForPricing.setText("￥" + storeListBean.getActualPrice());

        customCancleViewHolder.mLlCustomconetRootLayoutOrderCustomConttent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = OrderDetailsActivity.call2OrderDetailsActivity(mContext, storeListBean.getId(), storeListBean.getDetailId() + "");
                mContext.startActivity(intent);

            }
        });
        customCancleViewHolder.mIvDelItemCancelOrderHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

              //  ToastUtils.makeText("删除订单");
                showGotGoodsDialog(position,"确定删除订单","取消","确定", Contans.DELETE_ORDER_TYPE);
            }
        });

    }
}
